package features.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class Main1 {
    public static void main(String[] args) {

        Service1 service1 = new Service1Impl();
        service1.loan();

        Service1 proxy = (Service1) Proxy.newProxyInstance(Main1.class.getClassLoader(), service1.getClass().getInterfaces(), new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws InvocationTargetException, IllegalAccessException {
                System.out.println("proxy invoke before");
                Object result = method.invoke(service1,args);
                System.out.println("proxy invoke after");
                return result;
            }
        });
        proxy.loan();
        proxy.order();
    }
}
